﻿using GN.Pay.TradeChannel.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel
{
    /// <summary>
    /// 交易通道异常帮助
    /// </summary>
    [Serializable]
    public static class TradeChannelExceptionUtils
    {
        /// <summary>
        /// 抛出签名异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowSignFailException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.SignFail, channelId, message);
        }

        /// <summary>
        /// 抛出签名异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowSignFailException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.SignFail, channel.ChannelId, message);
        }

        /// <summary>
        /// 抛出配置出错而产生的异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowConfigureException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.Configure, channelId, message);
        }

        /// <summary>
        /// 抛出配置出错而产生的异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowConfigureException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.Configure, channel.ChannelId, message);
        }

        /// <summary>
        /// 抛出由于接口错误而产生的异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowInterfaceException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.Interface, channelId, message);
        }

        /// <summary>
        /// 抛出由于接口错误而产生的异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowInterfaceException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.Interface, channel.ChannelId, message);
        }

        /// <summary>
        /// 抛出由于客户请求错误而产生的异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowClientRequestException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.ClientRequest, channelId, message);
        }

        /// <summary>
        /// 抛出由于客户请求错误而产生的异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowClientRequestException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.ClientRequest, channel.ChannelId, message);
        }

        /// <summary>
        /// 抛出由于客户请求验证而产生的异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowClientRequestValidationException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.ClientRequestValidation,channelId, message);
        }

        /// <summary>
        /// 抛出由于客户请求验证而产生的异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowClientRequestValidationException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.ClientRequestValidation, channel.ChannelId, message);
        }

        /// <summary>
        /// 抛出由于网络出错而产生的异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowNetworkException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.Network, channelId, message);
        }

        /// <summary>
        /// 抛出由于网络出错而产生的异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowNetworkException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.Network, channel.ChannelId, message);
        }

        /// <summary>
        /// 抛出由于通道验证而产生的的异常
        /// </summary>
        /// <param name="channelId">通道Id</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowChannelValidationException(string channelId, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.ChannelValidataion, channelId, message);
        }

        /// <summary>
        /// 抛出由于通道验证而产生的的异常
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static TradeChannelException ThrowChannelValidationException(this IChannel channel, string message)
        {
            throw new TradeChannelException(TradeChannelErrorCode.ChannelValidataion, channel.ChannelId, message);
        }
    }
}
